﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.IO;
using System.Security.Cryptography;
using Microsoft.Win32;

namespace QL_BENHVIEN
{
    class helper
    {
        public string Server { get; set; }
        public string Database { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }


        public helper()
        {
            string line = "";
            StreamReader sr = new StreamReader("ConnectString.con");
            
                while ((line = sr.ReadToEnd().Trim()) != "")
                {
                 this.Server = line;
                 this.Database = line;
                 this.UserName = line;
                 this.Password = line;
                }
                sr.Close();
          
        }
        public SqlConnection GetConnect()
        {
            if (this.UserName != "")
                return new SqlConnection("Data Source=" + this.Server + ";Initial Catalog=" + this.Database + ";User Id=" + this.UserName + ";Password=" + this.Password + ";");
            else
                return new SqlConnection("Data Source=" + this.Server + ";Initial Catalog=" + this.Database + ";Integrated Security=True");
        }

       

        public static void WriteFile(string server, string data, string uid, string pass)
        {
            StreamWriter writer = new StreamWriter("ConnectString.con");
            writer.Flush();
            writer.WriteLine(server);
            writer.WriteLine(data);
            writer.WriteLine(uid);
            writer.WriteLine(pass);
            
            writer.Close();
        }
    }
    }

